home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / 8bit / cislib_a / compar.act < prev    next >
Text File  |  1995-04-22  |  1KB  |  71 lines

  1. ; Compare - Check if two files are
  2. ;   the same.
  3.  
  4. ; by Mark Rose - March, 1985
  5.  
  6.  
  7. PROC CmpFile( BYTE f1, f2 )
  8.     BYTE c1, c2
  9.     CARD i,
  10.          nErrors
  11.  
  12.     i = 0
  13.     nErrors = 0
  14.   ; Until end-of-file, compare a char
  15.   ; from each file and bump count of
  16.   ; errors, if not the same.
  17.     DO
  18.       ; Get one character from each file.
  19.         c1 = GetD( f1 )
  20.         c2 = GetD( f2 )
  21.         IF (EOF(f1)#0) OR (EOF(f2)#0) THEN
  22.             EXIT
  23.         FI
  24.       ; If chars dont compare, inform
  25.       ; user.
  26.         IF c1 # c2 THEN
  27.             nErrors ==+ 1
  28.             PrintF( "%H: %H %H%E", i, c1, c2 )
  29.         FI
  30.         i ==+ 1
  31.     OD
  32.     IF (EOF(f1)#0) AND (EOF(f2)=0) THEN
  33.         PrintE( "File 1 is shorter" )
  34.     ELSEIF (EOF(f1)=0) AND (EOF(f2)#0) THEN
  35.         PrintE( "File 2 is shorter" )
  36.     ELSE
  37.         IF nErrors = 0 THEN
  38.             PrintE( "Files compare exactly" )
  39.         ELSE
  40.             PrintE( "Files are the same length" )
  41.         FI
  42.     FI
  43. RETURN
  44.  
  45.  
  46.  
  47. PROC Compare()
  48.   ; Need strings for two file names.
  49.     BYTE ARRAY fn1( 30 ), fn2( 30 )
  50.  
  51.   ; Get the two input files
  52.     Print( "File 1: " )
  53.     InputS( fn1 )
  54.     Print( "File 2: " )
  55.     InputS( fn2 )
  56.  
  57.   ; and open them.
  58.     Close( 1 )
  59.     Open( 1, fn1, 4, 0 )
  60.     Close( 2 )
  61.     Open( 2, fn2, 4, 0 )
  62.  
  63.   ; Perform the compare
  64.     CmpFile( 1, 2 )
  65.  
  66.   ; and close up.
  67.     Close( 1 )
  68.     Close( 2 )
  69. RETURN
  70.  
  71. #############################################################################################